import { _decorator, Component, director, Label, Node, find, ProgressBar, Vec3, v3, Sprite } from 'cc';
const { ccclass, property } = _decorator;

const pos: Vec3 = v3();

@ccclass('LoadingPanel')
export class LoadingPanel extends Component {

    progressBar: Node = null;
    Text: Node = null;

    Show(sceneName: string) {
        let MinIndex: number = 0;
        this.progressBar = this.node.getChildByName("进度条顶");
        this.Text = this.node.getChildByName("百分比")


        director.preloadScene(sceneName, (completedCount: number, totalCount: number, item: any) => {
            var progress = completedCount / totalCount * 1.5;
            MinIndex = progress > MinIndex ? progress : MinIndex;
            if (MinIndex > 0.99) MinIndex = 0.99;
            this.progressBar.getComponent(Sprite).fillRange = MinIndex;
            this.Text.getComponent(Label).string = `正在加载：${(MinIndex * 100).toFixed()}%`;
        }, () => {

        });
        director.loadScene(sceneName, () => {
            this.node.active = false;
            this.progressBar.getComponent(Sprite).fillRange = 0;
        });
    }

}